package com.yu.crm.service.impl;

import com.yu.crm.domain.pojo.CrmRouteUser;
import com.yu.crm.mapper.CrmRouteUserMapper;
import com.yu.crm.service.ICrmRouteUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yxzz.common.config.UserCacheManager;
import com.yxzz.common.helper.DataHelpers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 路线人员表 服务实现类
 * </p>
 *
 * @author pan
 * @since 2020-09-28
 */
@Service
public class CrmRouteUserService extends ServiceImpl<CrmRouteUserMapper, CrmRouteUser> implements ICrmRouteUserService {

    @Resource(name = "userCacheManager")
    private UserCacheManager userCacheManager;

    @Override
    public void insert(CrmRouteUser crmRouteUser) {
        String openId = userCacheManager.getCurrentUser().getOpenId();
        String userId = userCacheManager.getCurrentUser().getUserId();
        if (DataHelpers.isNotEmpty(openId)) {
            crmRouteUser.setUserId(openId);
        }
        if (DataHelpers.isNotEmpty(userId)) {
            crmRouteUser.setUserId(userId);
        }
        this.save(crmRouteUser);
    }
}
